<template>
	<view>

		<u-subsection :list="list" :current="curNow" @change="sectionChange"></u-subsection>


		<view style="margin-top: 24upx;
				border-radius: 20upx;margin-left: 24upx;margin-right: 24upx;">

			<view v-for="(item,index) in mineCodeList" :key="index"
				style="background: #FFFFFF;margin-top: 24upx;border-radius: 24upx;">

				<view
					style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;border-bottom: 1upx solid #dee2eb">
					<view style="display: flex;flex-direction: row;align-items: center;margin-bottom: 10upx;">
						<image style="width: 40upx;height: 40upx;margin-top: 24upx;margin-left: 24upx;"
							src="../../static/icon/zuanshi.png" mode=""></image>
						<view style="color: #202021;font-weight: bold;font-size: 30upx;margin-left: 16upx;
							margin-top: 24upx;width: 450upx;">
							<text style="font-size: 26upx;color: #303133;">{{item.title}}</text>
						</view>
					</view>


					<view style="background-color: #252526;color: #EDCF87;
							font-size: 22upx;height: 40upx;margin-right: 16upx;border-radius: 20upx;
							line-height: 40upx;padding-left: 10upx;padding-right: 10upx;margin-top: 24upx;
							margin-right: 16upx;margin-bottom: 10upx;">

						<text v-if="item.resourceType===1">小程序</text>
						<text v-else-if="item.resourceType===2">网站源码</text>
					</view>


				</view>

				<view style="display: flex;flex-direction: row;align-items: center;" @click="detail(item.id)">
					<image
						style="width: 160upx;height: 160upx;border-radius: 16upx;margin-top: 24upx;margin-left: 24upx;"
						:src="item.cover" mode="aspectFill"></image>
					<view style="display: flex;flex-direction: column;margin-left: 24upx;margin-top: 24upx;">
						<view style="font-size: 28upx;color: #191919;">{{item.title}}</view>
						<view style="color: #FF4E4C;font-size: 30upx;font-weight: bold;margin-top: 4upx;">
							￥{{item.price}}</view>
						<view style="color: #9E9E9E;font-size: 24upx;margin-top: 24upx;">购买时间:{{item.buyTime}} </view>
					</view>

				</view>



				<view
					style="display: flex;margin-top: 40upx;flex-direction: row;justify-content: space-between;
					align-items: center;" @click="getResourceCode(item.attachmentInfo,item.title)">

					<view style="margin-left: 24upx;font-size: 20upx;">已有{{item.viewCount}}小伙伴查看</view>

					<view style="background-color: #4CD964;color: #ffffff;
						font-size: 28upx;height: 46upx;margin-right: 16upx;border-radius: 23upx;line-height: 46upx;
						padding-left: 10upx;padding-right: 10upx;margin-bottom: 10upx;"
						>立即查看</view>
				</view>


			</view>

		</view>

		<view v-show="isEmpty" style="margin-top: 50%;">

			<u-empty mode="data" icon="https://cdn.uviewui.com/uview/demo/empty/list.png">
			</u-empty>
		</view>


		<view class="popup" v-show="show">
			<view class="popup-info">
				<view style="color: #303133;text-align: center;font-size: 26upx;font-weight: bold;">{{title}}</view>
				<view style="color: #191919;font-size: 28upx;margin-top: 48upx;width: 500upx;word-wrap: break-word; 
word-break: normal;background-color: #f3f3f3;border-radius: 20upx;padding: 20upx 20upx">{{attachmentInfo}}</view>

				<view
					style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;margin-top: 56upx;">
					<view style="background: #F4F4F4;color: #191919;font-size: 28upx;width: 240upx;height: 80upx;margin-left: 30upx;
							border-radius: 32upx;text-align: center;line-height: 80upx;" @tap="cancel">取消</view>
					<view style="background: #4CD964;color: #FFFFFF;font-size: 28upx;width: 240upx;
							height: 80upx;margin-right: 30upx;border-radius: 32upx;text-align: center;line-height: 80upx;"
						@tap="copy(attachmentInfo)">复制
					</view>
				</view>
			</view>
		</view>






	</view>
</template>

<script>
	import {
		mine_resource_code
	} from '../../api/resource_code.js'
	export default {
		data() {
			return {
				background: {
					'background-image': 'linear-gradient(45deg, rgb(0, 0, 0), rgb(0, 0, 0))'
				},
				list: ['积分获取', '免费获取'],
				curNow: 0,
				isEmpty: false,
				show: false,
				userinfo: {},
				title: "",
				mineCodeList: [],
				foodPublishList: [],
				attachmentInfo: ""
			}
		},
		onLoad() {
			this.sectionChange(0)
		},
		methods: {
			// 点击弹窗取消
			cancel() {
				this.show = false;
			},
			// 点击弹窗确认
			copy(value) {
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							title: '复制成功',
							icon:'none'
						})
					}
				});

			},
			getResourceCode(data, title) {
				this.show = true
				console.log(data)
				this.title = title
				this.attachmentInfo = data
			},
			detail(id) {
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			sectionChange(index) {
				this.mineCodeList = []
				this.curNow = index;
				console.log(index)
				// 查询付费获取到资源
				if (index === 0) {

					this.mineCodeList = []
					let params = {}
					params.type = 1
					mine_resource_code(params).then(res => {
						if (res.data !== null) {
							this.mineCodeList = res.data
							this.isEmpty = false
						} else {
							this.isEmpty = true
						}
					})
				} else {
					this.mineCodeList = []
					// 查询免费获取到资源
					let params = {}
					params.type = 2
					mine_resource_code(params).then(res => {
						if (res.data !== null) {
							this.mineCodeList = res.data
							this.isEmpty = false
						} else {
							this.isEmpty = true
						}

					})

				}


			}

		}
	}
</script>

<style lang="scss" scoped>
	.popup-info {
		position: fixed;
		width: 600upx;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		padding: 40upx;
		border-radius: 20upx;
		background-color: #fff;
		z-index: 9999;
	}

	.popup {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 9998;
	}
</style>
